package tables;

import java.util.ArrayList;

public class Album extends AbstractEntity{
	private int year;
	private ArrayList<String> freeDBId;
	
	static int virtualId = -1;
	
	public Album(int id, String name, int year) {
		super(id, name);
		this.year = year;
		this.freeDBId = new ArrayList<String>();
	}
	
	public Album(int id, String name, int year, ArrayList<String> freeDBId) {
		super(id, name);
		this.year = year;
		this.freeDBId = freeDBId;
	}
	
	//****** getters *******\\
	
	public int getYear() {
		return year;
	}
	
	public ArrayList<String> getFreeDBId() {
		return freeDBId;
	}
	
	public String getFreeDBIdToString(){
		if(getFreeDBId().isEmpty()){
			return "";
		}else{
			String result = getFreeDBId().get(0);
			for(int i = 1; i < getFreeDBId().size(); i++){
				result += ", " + getFreeDBId().get(i);
			}
			return result;
		}
	}
	//********* setters *****************\\
	
	public void setFreeDBId(ArrayList<String> freeDBId) {
		this.freeDBId = freeDBId;
	}
	
	public void setYear(int year){
		this.year = year;
	}
	
	//the length is a series a(n) = 8n+3(n-1)
	//we will allow 3 different ids 
	public void addFreeDBId(String freeDBId){
		if(this.freeDBId.size() < 3){
			this.freeDBId.add(freeDBId);
		}
	}
	//********* virtualId tools *********\\
	
	/**
	 * if table is empty, then virtual id is set to 0,
	 * so when we call to addVirtualId we get id 1 - the first row;
	 * @param realVirtualId
	 */
	public static void initalizeVirtualId(int realVirtualId){
		virtualId = realVirtualId;
	}
	
	public static int getVirtualId() {
		return virtualId;
	}
	
	public static void addVirtualId(){
		virtualId++;
	}
	
	public static boolean isInitalized(){
		if(virtualId < 0){
			return false;
		}else{
			return true;
		}
	}
	
	
	public int fixId(){
		if(!isValidId()){
			addVirtualId();
			setId(getVirtualId());
		}
		return getId();
	}
	

	
	public String toString(){
		return super.toString() + "year: " + getYear() + "\n" +
								  "freeDBId: " + getFreeDBId() + "\n";
	}
	
}














